//
// C:\Program Files (x86)\FlashDevelop\Tools\flexsdk\frameworks\libs\player\10.0\playerglobal.swc\flash\events\EventDispatcher
//
package flash.events
{
	import flash.events.Event;
	import flash.utils.Dictionary;


	public class EventDispatcher
	{
		
		private var _event:Dictionary;
		

		public function EventDispatcher ()
		{
			_event = new Dictionary();
		}
		

		public function addEventListener (evtType:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false) : void;
		{
			if (!_event[evtType]) {
				_event[evtType] = [];
			}
			_event[evtType].push(listener);
		}
		
		public function dispatchEvent (event_:Event) : Boolean
		{
			var arrEvent:Array = this._event[event_.type];
			if(!arrEvent)
				return;
			if(!event_.currentTarget)
				event_.currentTarget = this;
			for (var i = 0; i < arrEvent.length; i++)
			{
				arrEvent[i](event_);
				if (event_.skip)
					return false;
			}
			return true;
		}


		
		public function hasEventListener (evtType:String) : Boolean
		{
			return !!_event[evtType];
		}

		
		public function removeEventListener (evtType:String, listener:Function, useCapture:Boolean = false)
		{
			if (!listener)
				_event[evtType] = [];
			else
			{
				var ind:int = findEvent(evtType, listener);
				if (ind != -1)
					_event[evtType].splice(ind, 1);
			}
		}
		
		
		private function findEvent(evtType:String, listener:Function):int
		{
			var arrEvent:Array = _event[evtType];
			var ind:int = -1;
			for (var i:int = 0; i < arrEvent.length; i++)
			{
				if (arrEvent[i] === listener) {
					return i;
				}
			}
			return ind;
		}

		public function toString () : String
		{
			return "[object EventDispatcher]";
		}

		
		public function willTrigger (type:String) : Boolean
		{
			
		}
	}
}
